package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbOpenCapacityAuthentication;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbOpenCapacityAuthenticationDao {
    @Results(id = "pcbOpenCapacityAuthenticationResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "factory_id", property = "factoryId", jdbcType = JdbcType.INTEGER),
//            @Result(column = "apply_content", property = "applyContent", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "apply_files", property = "applyFiles", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "h3c_remark", property = "h3cRemark", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "h3c_files", property = "h3cFiles", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "apply_content2", property = "applyContent2", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "apply_files2", property = "applyFiles2", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_status", property = "approveStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "approve_user_id", property = "approveUserId", jdbcType = JdbcType.INTEGER),
//            @Result(column = "approver1", property = "approver1", jdbcType = JdbcType.INTEGER),
//            @Result(column = "approver2", property = "approver2", jdbcType = JdbcType.INTEGER),
            @Result(column = "approve_user_name", property = "approveUserName", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "approve_user_name1", property = "approveUserName1", jdbcType = JdbcType.VARCHAR),
//            @Result(column = "approve_user_name2", property = "approveUserName2", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })

    /*
     *查询单个
     */
    @Select("<script> " +
            "select * " +
            " from " + DB2TableName.PCB_OPEN_CAPACITY_AUTHENTICATION +
            " where id = #{id}" +
            "</script>")
    PcbOpenCapacityAuthentication getById(@Param("id") Integer id);

    /*
     *查询指定行数据
     */
    @Select("<script> " +
            "select id, factory_id, approve_status, approve_user_id, approve_user_name, create_time, create_user, update_time, update_user, status, sort " +
            "from " + DB2TableName.PCB_OPEN_CAPACITY_AUTHENTICATION +
            "<where>" +
            "<if test='factoryId != null'>" +
            " and (factory_id = #{factoryId})" +
            "</if>" +
            "<if test='approveStatus != null '>" +
            " and (approve_status = #{approveStatus})" +
            "</if>" +
            "</where>" +
            "order by id " +
            "</script>")
    @ResultMap(value = "pcbOpenCapacityAuthenticationResultMap")
    List<PcbOpenCapacityAuthentication> getAllByLimit(PcbOpenCapacityAuthentication param);

    /*
     *查询指定行数据
     */
    @Select("<script> " +
            "select id, factory_id, approve_status, approve_user_id, approve_user_name, create_time, create_user, update_time, update_user, status, sort " +
            "from " + DB2TableName.PCB_OPEN_CAPACITY_AUTHENTICATION +
            "<where>" +
            "<if test='factoryId != null'>" +
            " and (factory_id = #{factoryId})" +
            "</if>" +
            "<if test='approveStatus != null '>" +
            " and (approve_status = #{approveStatus})" +
            "</if>" +
            "</where>" +
            "order by id desc" +
            "</script>")
    @ResultMap(value = "pcbOpenCapacityAuthenticationResultMap")
    List<PcbOpenCapacityAuthentication> getAllByLimitByDesc(PcbOpenCapacityAuthentication param);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_OPEN_CAPACITY_AUTHENTICATION + " (factory_id, approve_status, approve_user_id, approve_user_name, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{factoryId},  #{approveStatus}, #{approveUserId}, #{approveUserName}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insert(PcbOpenCapacityAuthentication param);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_OPEN_CAPACITY_AUTHENTICATION + " where id = #{id} ")
    Integer delete(@Param("id") Integer id);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_OPEN_CAPACITY_AUTHENTICATION +
            "<set>" +
            "<if test='factoryId != null'>" +
            "factory_id = #{factoryId}," +
            "</if>" +
//            "<if test='applyContent != null and applyContent != \"\"'>" +
//            "apply_content = #{applyContent}," +
//            "</if>" +
//            "<if test='h3cRemark != null and h3cRemark != \"\" '>" +//and companyWebsite != ""
//            "h3c_remark = #{h3cRemark}," +
//            "</if>" +
//            "<if test='applyContent2 != null and applyContent2 != \"\" '>" +//and companyWebsite != ""
//            "apply_content2 = #{applyContent2}," +
//            "</if>" +
            "<if test='approveStatus != null'>" +
            "approve_status = #{approveStatus}," +
            "</if>" +
            "<if test='approveUserId != null and approveUserId != \"\"'>" +
            "approve_user_id = #{approveUserId}," +
            "</if>" +
            "<if test='approveUserName != null and approveUserName != \"\"'>" +
            "approve_user_name = #{approveUserName}," +
            "</if>" +
//            "<if test='approver1 != null'>" +
//            "approver1 = #{approver1}," +
//            "</if>" +
//            "<if test='approver2 != null'>" +
//            "approver2 = #{approver2}," +
//            "</if>" +
//            "<if test='approveUserName1 != null and approveUserName1 != \"\"'>" +
//            "approve_user_name1 = #{approveUserName1}," +
//            "</if>" +
//            "<if test='approveUserName2 != null and approveUserName2 != \"\"'>" +
//            "approve_user_name2 = #{approveUserName2}," +
//            "</if>" +
            "<if test='createTime != null '>" +
            "create_time = #{createTime}," +
            "</if>" +
            "<if test='updateTime != null '>" +
            "update_time = #{updateTime}," +
            "</if>" +
            "<if test='status != null'>" +
            "status = #{status}," +
            "</if>" +
            "<if test='sort != null'>" +
            "sort = #{sort} " +
            "</if>" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    Integer update(PcbOpenCapacityAuthentication param);
}
